package com.iot08.api.service;

import com.alibaba.fastjson.JSONObject;
import com.iot08.common.constant.Const;
import com.iot08.common.entity.app.PpChatGroupMessage;
import com.iot08.common.service.base.BaseService;
import com.iot08.common.utils.DateUtil;
import com.iot08.common.utils.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @version 1.0
 * @Description:
 * @author: Rock
 * @time: 2021/1/22 18:28
 */
@Slf4j
@Service
public class PpChatGroupMessageService extends BaseService<PpChatGroupMessage> {


    /**
     * @param data
     * @time: 2021/1/23 9:51
     * @author: Rock
     * @version 1.0
     */
    public PpChatGroupMessage add(JSONObject data) {
        PpChatGroupMessage ppChatGroupMessage = new PpChatGroupMessage();
        ppChatGroupMessage.setPcgid(data.getString("pcgid"));
        ppChatGroupMessage.setSender(data.getString("sender"));
        ppChatGroupMessage.setAcceptor(data.getString("acceptor"));
        ppChatGroupMessage.setTime(DateUtil.nowTimestampToDouble());
        ppChatGroupMessage.setExpiryAt(DateUtil.getSystemExpiryAt());

        ppChatGroupMessage.setContent(data.getString("content"));
        if (data.containsKey("size")) {
            ppChatGroupMessage.setSize(data.getInteger("size"));
        }else{
            ppChatGroupMessage.setSize(0);
        }

        return mongoTemplate.save(ppChatGroupMessage);
    }
}
